home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / dos_log.zip / LOG.ASM < prev    next >
Assembly Source File  |  1994-04-13  |  7KB  |  247 lines

  1. ;*******************************************
  2. ;FILENAME:    LOG.ASM
  3. ;FILE FORMAT:    COM
  4. ;AUTHOR:    MIKE TIHEN
  5. ;I-NET ADDRESS:    c600689@mizzou1.missouri.edu
  6. ;DATE WRITTEN:    4/13/94
  7. ;*******************************************
  8.  
  9. COMMENT    /*
  10.     This file was written to keep a running log of DOS commands
  11.     issued. It intercepts interrupt 21H function 0AH and grabs
  12.     a copy of the buffered input string pointed to by DS:DX. The
  13.     actual string is at DS:DX+2. DS:DX points to the maximum
  14.     allowable characters to be accepted before signaling a beep,
  15.     and simply waiting for a backspace or a carriage return. This
  16.     value for DOS is typically 80H. The next byte DS:DX+1 contains
  17.     the actual number of characters that were entered. Care must be
  18.     taken not to disturb any data registers are segment registers,
  19.     as DOS still has to act on that same string.
  20.  
  21.     IMPORTANT - Any program that intercepts INT 21H function 0AH
  22.     prior to this program could render it useless. Such an example
  23.     would be DOSKEY. It is recommended that an alternative program
  24.     such as NDE.COM be used. It does lack some of the features that
  25.     DOSKEY has, but it doesn't mess with INT 21H function 0AH.
  26.     */
  27.  
  28. PAGE    55,132                ;set up page control for .lst file
  29.  
  30. .386                    ;turn on 386 instruction usage
  31.  
  32. ATTRIB        EQU    6H        ;hidden and system
  33.                     ;0 = normal
  34.                     ;2 = hidden
  35.                     ;4 = system
  36. ACCESS        EQU    02H        ;read/write and SHAREd
  37.  
  38. CREATE_FILE    EQU    5BH        ;some useful DOS functions
  39. OPEN_FILE    EQU    3DH
  40. CLOSE_FILE    EQU    3EH
  41. WRITE_FILE    EQU    40H
  42. FILE_POINTER    EQU    42H
  43.  
  44. CODE_SEG    SEGMENT PARA 'CODE' PUBLIC USE16
  45.         ASSUME    CS:CODE_SEG,DS:CODE_SEG,SS:CODE_SEG,ES:CODE_SEG
  46.  
  47.     ORG    0100H
  48. BEGIN:    JMP    INIT
  49. FILENAME    DB    'C:\LOG.DAT',0    ;null terminated path and filename
  50.                     ;this path:filename can be anything
  51. HANDLE        DW    ?
  52. BAD_PATH    DB    'The path for the log file was not found.',0DH,0AH,'$'
  53. NO_HANDLES    DB    'Insufficient FILE handles in config.sys.',0DH,0AH,'$'
  54. ACCESS_DENIED    DB    'Access to the log file is denied!',0DH,0AH,'$'
  55. UNKNOWN_ERR    DB    'An unknown error has occurred',0DH,0AH,'$'
  56. DAY        DW    ?        ;day
  57.         DB    '-'
  58. MONTH        DW    ?        ;month
  59.         DB    ' '
  60. HOUR        DW    ?        ;hour
  61.         DB    ':'
  62. MINUTE        DW    ?        ;minute
  63.         DB    ' '
  64. LINEFEED    DB    0DH,0AH
  65. DX_STORAGE    DW    ?        ;temp storage for DX register
  66. INPUT_LENGTH    DW    ?        ;length of input string storage
  67. OLD_21H_OFF    DW    ?        ;far pointer to old int21 handler
  68. OLD_21H_SEG    DW    ?
  69.  
  70. int21    PROC    FAR
  71.     CMP    AH,0AH            ;is it buffered input function
  72.     JNE    PASSIT            ;no, pass it to old handler
  73.     PUSHF                ;yes, give it to the old handler 1st
  74.     CALL    DWORD PTR CS:OLD_21H_OFF
  75.     PUSHA                ;save all registers used
  76.     PUSH    ES            ;save DOS's ES
  77.     MOV    AX,DS            ;save DOS's DS in ES
  78.     MOV     ES,AX
  79.     PUSHF                ;save flags from INT 21H func 0AH
  80.  
  81.     ;using DOS's DS here
  82.     INC    DX            ;DX points to the input length
  83.     MOV    BX,DX
  84.     MOV    AL,BYTE PTR [BX]    ;get the input length
  85.     CMP    AL,0            ;was it a plain enter
  86.     JE    SKIP            ;yes, not interested in it
  87.                     ;no, grab it
  88.     ;switching to TSR's DS
  89.     MOV    CX,CS
  90.     MOV    DS,CX
  91.     MOVZX    CX,AL            ;AL still has input length
  92.     MOV    INPUT_LENGTH,CX        ;save it for later
  93.     INC    DX            ;DX points to the input string
  94.     MOV    DX_STORAGE,DX        ;save DX pointing to input string
  95.  
  96.     ;date and time stamp the input
  97.     MOV    AH,2AH            ;get the date
  98.     INT    21H
  99.     MOVZX    AX,DH            ;get the day
  100.     MOV    BL,0AH
  101.     DIV    BL            ;convert it to ASCII
  102.     ADD    AX,3030H
  103.     XCHG    AL,AL
  104.     MOV    DAY,AX            ;store it
  105.     MOVZX    AX,DL            ;get the month
  106.     MOV    BL,0AH
  107.     DIV    BL            ;convert it to ASCII
  108.     ADD    AX,3030H
  109.     XCHG    AL,AL
  110.     MOV    MONTH,AX        ;store it
  111.  
  112.     MOV    AH,2CH            ;get the time
  113.     INT    21H
  114.     MOVZX    AX,CH            ;get the hour
  115.     MOV    BL,0AH
  116.     DIV    BL            ;convert it to ASCII
  117.     ADD    AX,3030H
  118.     XCHG    AL,AL
  119.     MOV    HOUR,AX            ;store it
  120.     MOVZX    AX,CL            ;get the minute
  121.     MOV    BL,0AH
  122.     DIV    BL            ;convert it to ASCII
  123.     ADD    AX,3030H
  124.     XCHG    AL,AL
  125.     MOV    MINUTE,AX        ;store it
  126.  
  127.     ;open the file
  128.     MOV    AL,ACCESS        ;set the access rights to read/write
  129.     LEA    DX,FILENAME        ;DS:DX = pointer to filename
  130.     MOV    AH,OPEN_FILE
  131.     INT    21H
  132.     JC    SKIP            ;major error, file could have
  133.                     ;been deleted
  134.     MOV    HANDLE,AX        ;otherwise get the handle
  135.  
  136.     ;move the file pointer to end of the file
  137.     MOV    BX,HANDLE
  138.     MOV    AL,2            ;file pointer based off of end
  139.     MOV    CX,0            ;0 displacement
  140.     MOV    DX,0
  141.     MOV    AH,FILE_POINTER
  142.     INT    21H
  143.  
  144.     ;write the date and time to the end of the file
  145.     MOV    BX,HANDLE
  146.     MOV    CX,0CH            ;number of chars to write
  147.     LEA    DX,DAY            ;DS:DX points to date and time stamp
  148.     MOV    AH,WRITE_FILE
  149.     INT    21H
  150.  
  151.     ;write the collected data to the end of the file
  152.     MOV    BX,HANDLE
  153.     MOV    DX,DX_STORAGE        ;DS:DX points to the string
  154.     MOV    CX,INPUT_LENGTH        ;get the number of chars to write
  155.     MOV    AH,WRITE_FILE
  156.     ;switching to DOS's DS
  157.     PUSH    ES            ;must use PUSH's and POP's here
  158.     POP    DS
  159.     INT    21H
  160.  
  161.     ;switching to TSR's DS
  162.     MOV    AX,CS
  163.     MOV    DS,AX
  164.     ;write the carriage return and linefeed to the end of the file
  165.     MOV    BX,HANDLE
  166.     MOV    CX,02H            ;number of chars to write
  167.     LEA    DX,LINEFEED        ;DS:DX points to linefeed
  168.     MOV    AH,WRITE_FILE
  169.     INT    21H
  170.  
  171.     ;close the file
  172.     MOV    BX,HANDLE
  173.     MOV    AH,CLOSE_FILE
  174.     INT    21H
  175.  
  176. SKIP:    POPF                ;reset flags from INT 21H func 0AH
  177.     MOV    AX,ES            ;get DOS's DS back from ES
  178.     MOV    DS,AX
  179.     POP    ES            ;reset original ES
  180.     POPA                ;reset all registers used
  181.     JMP    DONE
  182. PASSIT:
  183.     JMP    DWORD PTR CS:OLD_21H_OFF
  184. DONE:    IRET
  185. int21    ENDP
  186.  
  187. INIT:
  188.     MOV    CX,ATTRIB        ;set the attributes to normal file
  189.     LEA    DX,FILENAME        ;DS:DX = pointer to filename
  190.     MOV    AH,CREATE_FILE        ;DOS 3.0+ create a new file requests
  191.     INT    21H
  192.     JC    FILE_ERROR
  193.     MOV    HANDLE,AX
  194.     JMP    NO_FILE_ERROR
  195. FILE_ERROR:
  196.     CMP    AX,03H            ;was the path bad?
  197.     JNE    NEXT1            ;no, check next possible error
  198.     MOV    AH,09H            ;yes, display the error
  199.     LEA    DX,BAD_PATH
  200.     INT    21H
  201.     JMP    BYE            ;and exit
  202. NEXT1:    CMP    AX,04H            ;were there enough handles
  203.     JNE    NEXT2            ;no, check next possible error
  204.     MOV    AH,09H            ;yes, display the error
  205.     LEA    DX,NO_HANDLES
  206.     INT    21H
  207.     JMP    BYE            ;and exit
  208. NEXT2:    CMP    AX,05H            ;was access to the file denied
  209.     JNE    NEXT3            ;no, check next possible error
  210.     MOV    AH,09H            ;yes, display the error
  211.     LEA    DX,ACCESS_DENIED
  212.     INT    21H
  213.     JMP    BYE            ;and exit
  214. NEXT3:    CMP    AX,50H            ;does the file exists already?
  215.     JNE    UNKNOWN_ERROR        ;no, an unknown error occurred
  216.     JMP    NO_FILE_ERROR        ;if file exists it is not an error
  217. UNKNOWN_ERROR:
  218.     MOV    AH,09H            ;display unknown error
  219.     LEA    DX,UNKNOWN_ERR
  220.     INT    21H
  221.     JMP    BYE            ;and exit
  222. NO_FILE_ERROR:
  223.     MOV    AL,21H
  224.     MOV    AH,35H            ;read interrupt 21H's previous address
  225.     INT    21H
  226.     MOV    OLD_21H_SEG,ES        ;and save the offset and segment
  227.     MOV    OLD_21H_OFF,BX
  228.  
  229.     MOV    AL,21H            ;put in the new handler's address
  230.     MOV    AH,25H
  231.     LEA    DX,int21        ;DS:DX points to new routine
  232.     INT    21H
  233.  
  234.     LEA    DX,INIT            ;end of resident area
  235.     MOV    CL,04H            ;divide by 16
  236.     SHR    DX,CL            ;ro calculate no. of paragraphs
  237.     INC    DX            ;add 1 for saftey
  238.     MOV    AL,0            ;return code for DOS ERRORLEVEL
  239.     MOV    AH,31H            ;Terminate and Stay Resident
  240.     INT    21H
  241.  
  242. BYE:    MOV    AL,1            ;return code for DOS ERRORLEVEL
  243.     MOV    AH,4CH            ;properly exit to DOS 2.0+
  244.     INT    21H
  245. CODE_SEG    ENDS
  246.     END    BEGIN
  247.